#
# @lc app=leetcode.cn id=13 lang=python3
#
# [13] 罗马数字转整数
#


# @lc code=start
class Solution:
    def romanToInt(self, s: str) -> int:
        d = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000,
            'IV': -2,
            'IX': -2,
            'XL': -20,
            'XC': -20,
            'CD': -200,
            'CM': -200
        }
        length = ['M', 'D', 'C', 'L', 'X', 'V', 'I', 'IV', 'IX', 'XL', 'XC', 'CD', 'CM']
        num = 0
        for R in length:
            if R in s:
                num += d[R] * s.count(R)
        return num


# @lc code=end
